namespace CSharpPro._1009;

class Demo1
{
    // 修改为public以便外部调用
    public void PrintNarcissisticNumbers()
    {
        Console.Write("1000以内的水仙花数：");
        for (int num = 1; num < 1000; num++)
        {
            int unit = num % 10;
            int ten = (num / 10) % 10;
            int hundred = num / 100;
            // 用手动乘法替代Math.Pow，避免浮点误差
            if (unit * unit * unit + ten * ten * ten + hundred * hundred * hundred == num)
            {
                Console.Write(num + " ");
            }
        }
        Console.WriteLine(); // 换行，区分两个结果
    }
    
    public void PrintPrimesUnder100()
    {
        Console.Write("100以内的所有质数：");
        for (int num = 2; num < 100; num++)
        {
            bool isPrime = true;
            for (int i = 2; i * i <= num; i++)
            {
                if (num % i == 0)
                {
                    isPrime = false;
                    break;
                }
            }
            if (isPrime)
            {
                Console.Write(num + " ");
            }
        }
        Console.WriteLine();
    }
}